﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMTVision.Widgets.Framework;

namespace CMTVision.WidgetWeb.Widgets
{
    public partial class ContentWidget : BaseWidget
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            } 
        }

        protected void BindData()
        {
            ShowPanel.Visible = !IsInEditting;
            EditPanel.Visible = IsInEditting;
            if (!String.IsNullOrEmpty(State))
            {
                ContentLiteral.Text = State;
                ContentEditor.RadEditor.Content = State;
            }
            ContentEditor.RadEditor.Height = 20;
        }

        public override void Edit()
        {
            IsInEditting = true;
            ShowPanel.Visible = !IsInEditting;
            EditPanel.Visible = IsInEditting;
        }

        public override void Save()
        {
            IsInEditting = false;
            State = ContentEditor.RadEditor.Content;
            BindData();
            base.Save();
        }

        public override void Refresh()
        {
            base.Refresh();
            ShowPanel.Visible = !IsInEditting;
            EditPanel.Visible = IsInEditting;

        }
    }
}